﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MusicaTangible
{
    public enum Shapes { circle, square, cross, triangle, empty }

    abstract class Board
    {
        public int NumberOfRows { get; protected set; }
        public int NumberofColumms { get; protected set; }
        protected MusicProcessor parent;

        protected struct Row
        {
            public Shapes instrument;
            public Colors[] row;
        }

        protected Row[] myBoard;

        public abstract void Stop();

        protected void Initialize(int numberOfRows, int numberOfColumns)
        {
            this.NumberofColumms = numberOfColumns;
            this.NumberOfRows = numberOfRows;
            myBoard = new Row[numberOfRows];
            for (int i = 0; i < numberOfRows; i++)
            {
                myBoard[i].instrument = Shapes.empty;
                myBoard[i].row = new Colors[numberOfColumns];
                for (int j = 0; j < numberOfColumns; j++)
                {
                    myBoard[i].row[j] = Colors.empty;
                }
            }
        }

        public abstract void Update();

        public void SetInstrument(int rowNumber, Shapes shape)
        {
            myBoard[rowNumber].instrument = shape;
        }

        public void SetColor(int rowNumber, int columnNumber, Colors color)
        {
            myBoard[rowNumber].row[columnNumber] = color;
        }

        public Shapes GetInstrument(int rowIndex)
        {
            return this.myBoard[rowIndex].instrument;
        }

        public Colors GetColor(int rowIndex, int columnIndex)
        {
            return this.myBoard[rowIndex].row[columnIndex];
        }

        protected void PlaceShapeOnBoard(int row, Shapes shape)
        {
            this.SetInstrument(row, shape);
        }

        protected void PlaceColorOnBoard(int row, int column, Colors color)
        {
            this.SetColor(row, column - 1, color);
        }

        public void printBoard()
        {
            char symbol = '#';
            for (int i = 0; i < NumberOfRows; i++)
            {
                Shapes instrument = this.myBoard[i].instrument;
                switch (instrument)
                {
                    case Shapes.circle:
                        symbol = '1';
                        break;
                    case Shapes.triangle:
                        symbol = '2';
                        break;
                    case Shapes.square:
                        symbol = '3';
                        break;
                    case Shapes.cross:
                        symbol = '4';
                        break;
                    case Shapes.empty:
                        symbol = '-';
                        break;
                }
                System.Console.Write(symbol);
                System.Console.Write('|');
                for (int j = 0; j < NumberofColumms; j++)
			    {
                    Colors note = this.myBoard[i].row[j];
			        switch (note)
                    {
                        case Colors.red:
                            symbol = 'C';
                            break;
                        case Colors.orange:
                            symbol = 'D';
                            break;
                        case Colors.yellow:
                            symbol = 'E';
                            break;
                        case Colors.green:
                            symbol = 'F';
                            break;
                        case Colors.lightblue:
                            symbol = 'G';
                            break;
                        case Colors.blue:
                            symbol = 'A';
                            break;
                        case Colors.purple:
                            symbol = 'B';
                            break;
                        case Colors.empty:
                            symbol = '-';
                            break;
                    }
                    System.Console.Write(symbol);
                    System.Console.Write('|');
			    }
                System.Console.WriteLine();
            }
            System.Console.WriteLine();
        }

    }
}
